home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / qlib205.zip / QLIB.ZIP / SRC / STARTUP / C0.ASM next >
Assembly Source File  |  1997-07-08  |  7KB  |  310 lines

  1. ;PMODE/W v1.31+ (DOS/4GW) startup code
  2.  
  3. include qlib.inc
  4. include dos.inc
  5. include string.inc
  6. include math.inc
  7. include conio.inc
  8. include stdlib.inc
  9. include stdio.inc
  10. include errno.inc
  11. include process.inc
  12.  
  13. aaa_qlib segment dword use32  ;the 1st segment
  14. align 4
  15. db 'QLIB_MEM'   ;this MUST stay here! (used by qsetup)
  16.                 ;I place in code so it will be near beginning of EXE file
  17. HEAP_MAX dd -1         ;max that will be alloced for heap
  18.   ;NOTE:you should use pmwsetup to modify how much RAM the DOS extender
  19.   ; allocs.  The values here will have no effect how much it allocs unless
  20.   ; you are running under a DPMI server.  In which case pmwsetup has no
  21.   ; effect.  So use QSETUP which will modify these vales directly in the
  22.   ; EXE file which will guaranty you that RAM is avail for spawn...()
  23.   ; and other system calls
  24. HEAP_MIN dd 32 * 1024   ;min size needed to run
  25. aaa_qlib ends
  26.  
  27. .code
  28. NULLPROC proc
  29.   ret
  30. NULLPROC endp
  31.  
  32. .data
  33.   ;
  34.   _argv dd offset _args   ;this is argv!
  35.   _args dd 64 dup (0) ; the pointers
  36.   rational db 'RATIONAL DOS/4G',0
  37.   errno dw 0
  38.  
  39. .stack 16*1024  ;default 16K stack
  40.  
  41. .data?
  42.   _argstr db 128 dup (?) ; arguments copied from PSP
  43. public argc
  44.   argc label byte           ;needed for Watcom
  45.   _argc db ?             ; # of arguments
  46.     db 3 dup (?)
  47.   _pmmode db ?           ;mode  1=raw 2=XMS 4=VCPI 8=DPMI
  48.   _filename dd ?         ;pts to filename as loaded (also @ _argv[0*4])
  49.   _size dd ?             ;size of the EXE file after LINKing
  50.   _8087 db 3h            ; (for WATCOM compatibility) FIXED : v2.00 Beta #4
  51.   _fpu db ?              ;80387 FPU?  0=no 1=yes
  52.   _8kbufferseg dw ?      ;segment of 8k temp buffer (use as you like!)
  53.   _8kbuffer dd ?         ;linear addr of 8k buffer
  54.   _os_typ db ?           ;OS detected (see os.inc)
  55.   _os_ver_major db ?     ;OS version
  56.   _os_ver_minor db ?
  57.   _dos_ver_major db ?    ;DOS version
  58.   _dos_ver_minor db ?
  59.  
  60.   align 4 ;for speed!
  61.   selcode dw ?           ;selctor for code
  62.   selzero label word     ; " zero base
  63.   seldata dw ?           ; " data
  64.   dw ? ;make all perfectly aligned!
  65.   _environ dd ?          ; environment offset
  66.   _psp dd ?              ; PSP linear offset
  67.   _dta dd ?              ; DTA linear offset
  68.   _ds_ dw 0  ; both loaded into Sregs during int 10h
  69.   _es_ dw 0  ; Use these to send info to int 10h
  70.              ; there is an 8k buffer alloc during init for this purpose
  71.              ; it's _8kbufferseg (linear addr=_8kbuffer)
  72.   _dosXver dw ?    ;DOS extender version  (if possible)
  73.   _dosXtyp db ?    ;DOS extender type (0=PMODE/W 1=DOS/4GW 2=DOS32v3.5+)
  74.   _cpu label byte
  75.   _processor db ?  ;3=386 4=486 5=586 ...
  76.  
  77. ;private data
  78.   ;saved vectors
  79.   _int_10h df ?   ;df=6 bytes(for sel:offset)
  80.   _int_21h df ?
  81.  
  82.   align 4
  83.   _int dw ? ;interrupt # to call
  84.   _saved_ints db 1024 dup (?) ;saved RM ints
  85.  
  86. PMODEW equ 1
  87. include meminit.asm
  88. include osinit.asm 
  89. include mathinit.asm
  90. include keyinit.asm
  91.  
  92. .code
  93. ;Error messages
  94. Cantgetbase:
  95.   mov edx,"DPMI Error:Unable to get selector base.\r\n$"
  96.   jmp @f
  97. Cantsetint:
  98.   mov edx,"DPMI Error:Unable to set INT vects\r\n$"
  99.   jmp @f
  100. Cantgetint:
  101.   mov edx,"DPMI Error:Unable to get INT vects\r\n$"
  102.   jmp @f
  103. req131:
  104.   mov edx,"PMODE/W v1.31+ required\r\n$"
  105.   jmp @f
  106.  
  107. @@:
  108.   mov ah,9
  109.   int 21h
  110.   mov ax,4c00h
  111.   int 21h
  112.  
  113. externdef main:near
  114. externdef cstart_:near
  115.  
  116. align 4
  117.   ;required by Watcom C compiler for some reason but never gets called?
  118. cstart_:
  119. __entry32__:
  120.   jmp short begin
  121.   db 'WATCOM',0  ;keep this here in case you use DOS/4GW.EXE
  122. begin:
  123.  
  124.   sti
  125.   cld
  126.  
  127.   mov ax,ds
  128.   mov es,ax
  129.   mov fs,ax
  130.   mov gs,ax
  131.   mov seldata,ax
  132.   mov selcode,cs
  133.  
  134.   mov ax,0eeffh
  135.   int 31h
  136.   .if eax=='PMDW'
  137.     ;Using PMODE/W
  138.     mov _dosXtyp,DOSX_PMODEW
  139.     mov _pmmode,ch
  140.     mov _processor,cl
  141.     mov _dosXver,dx
  142.     .if dx<100h+31
  143.       jmp req131
  144.     .endif
  145.     jmp @f
  146.   .endif
  147.   mov ax,0a00h   ;detect DOS/4GW
  148.   mov esi,offset rational
  149.   int 31h
  150.   mov ds,cs:seldata   ;restore DS
  151.   .if !carry?
  152.     ;Using DOS/4GW
  153.     mov _dosXtyp,DOSX_DOS4GW
  154.     mov _dosXver,0
  155.   .else
  156.     ;DOS extender unknown
  157.     mov _dosXtyp,DOSX_UNKNOWN
  158.     mov _dosXver,0
  159.   .endif
  160.   mov ax,ds
  161.   mov es,ax
  162.   mov fs,ax
  163.   mov gs,ax
  164.   mov ax,1687h
  165.   int 2fh  ;detect DPMI host
  166.   .if ax==0
  167.     mov _pmmode,SRV_DPMI
  168.     mov _processor,cl
  169.   .else
  170.     mov _pmmode,SRV_VCPI ;assume VCPI (does not really matter)
  171.     mov _processor,3     ;assume 386 processor  (Processor detection?)
  172.   .endif
  173.  
  174. @@:
  175.   mov ah,62h    ;get PSP selector  (PMODE/W v1.31+)
  176.   int 21h
  177.   mov ax,6
  178.   int 31h
  179.   .if carry?
  180.     jmp Cantgetbase
  181.   .endif
  182.  
  183.   shl ecx,16
  184.   mov cx,dx
  185.   mov _psp,ecx
  186.  
  187.   mov bx,[ecx+44]  ;get enviroment selector
  188.   mov ax,6
  189.   int 31h
  190.   .if carry?
  191.     jmp Cantgetbase
  192.   .endif
  193.  
  194.   shl ecx,16
  195.   mov cx,dx
  196.   mov _environ,ecx
  197.  
  198.   mov ah,1ah
  199.   mov edx,_psp
  200.   add edx,80h
  201.   mov _dta,edx
  202.   int 21h  ;set DTA addr
  203.  
  204.   mov ax,100h   ;alloc 8k DOS memory for temp buffer
  205.   mov bx,8*1024/16
  206.   int 31h
  207.   jc outofram  ;within meminit.asm
  208.  
  209.   ;ax=RMODE segment
  210.   xor ecx,ecx
  211.   mov cx,ax
  212.   shl ecx,4
  213.   mov _8kbufferseg,ax
  214.   mov _8kbuffer,ecx
  215.  
  216. ;save ALL RM INTS
  217.   mov esi,0   ;the real mode INT table
  218.   mov edi,offset _saved_ints
  219.   mov ecx,256
  220.   rep movsd   ;save 1024 bytes!!!
  221.  
  222. ;save selected PM ints
  223.   mov ax,204h
  224.   mov bl,21h
  225.   int 31h
  226.   jc Cantgetint
  227.   mov wptr[_int_21h+4],cx
  228.   mov dptr[_int_21h+0],edx
  229.  
  230.   mov ax,204h
  231.   mov bl,10h
  232.   int 31h
  233.   jc Cantgetint
  234.   mov wptr[_int_10h+4],cx
  235.   mov dptr[_int_10h+0],edx
  236.  
  237. ;set PM ints
  238.   mov ax,205h
  239.   mov bl,10h
  240.   mov edx,offset _int10h
  241.   mov cx,cs
  242.   int 31h
  243.   jc Cantsetint
  244.  
  245. ;init all necessary stuff
  246.   call math_init
  247.   .if eax==ERROR
  248.     mov _fpu,0
  249.   .else
  250.     mov _fpu,3
  251.   .endif
  252.   call key_init
  253.  
  254.   include c0c1.asm  ;setup args
  255.  
  256.   call os_detect
  257.  
  258.   call alloc_init
  259.  
  260.   xor eax,eax
  261.   xor ebx,ebx
  262.   xor ecx,ecx
  263.   xor edx,edx
  264.   xor ebp,ebp
  265.   xor esi,esi
  266.   xor edi,edi
  267.  
  268.   .if _dosXtyp==DOSX_DOS4GW
  269.     int 3  ;call debugger if loaded
  270.   .endif
  271.  
  272. ;main()
  273.   push _environ
  274.   push _argv
  275.   push dptr _argc
  276.   call main  ;called as main(_argc,_argv,_environ)
  277.   add esp,12
  278. ;main()
  279.  
  280.   callp exit,al
  281. ;end of __entry32__
  282.  
  283. _c_exit proc
  284. ;restore all RM ints
  285.   mov esi,offset _saved_ints
  286.   mov edi,0
  287.   mov ecx,256
  288.   rep movsd
  289.  
  290. ;restore PM ints
  291.   mov ax,205h
  292.   mov bl,10h
  293.   mov cx,wptr[_int_10h+4]
  294.   mov edx,dptr[_int_10h+0]
  295.   int 31h
  296.   jc Cantsetint
  297.  
  298.   mov ax,205h
  299.   mov bl,21h
  300.   mov cx,wptr[_int_21h+4]
  301.   mov edx,dptr[_int_21h+0]
  302.   int 31h
  303.   jc Cantsetint
  304.   ret
  305. _c_exit endp
  306.  
  307. include c0c2.asm
  308.  
  309. end __entry32__
  310.